#include "HeadFile.h"

Fruit::Fruit(size_t x, size_t y,const char* image)
{
	this->pos.X = x;
	this->pos.Y = y;
	strcpy_s(this->image, image);
	this->next = nullptr;
	this->front = nullptr;
}

Fruit::~Fruit()
{
	if (this)
	{
		if (this->next != nullptr)
		{
			this->next->~Fruit();
		}
		return;
	}
	
}

void Fruit::Show()
{
	DrawFunc::Instance()->CN_DrawWithGreen(pos.X, pos.Y, this->image, DRAWINBUFFER);
	if (this->next == nullptr)
		return;
	else
		this->next->Show();
}

void Fruit::SetNext(Fruit* n)
{
	this->next = n;
}

void Fruit::SetFront(Fruit* n)
{
	this->front = n;
}

Fruit* Fruit::DeleteNode(size_t x, size_t y)
{

	if (this->pos.X == x && this->pos.Y == y)
	{
		return this;
	}
	if(this->next != nullptr)
	{
		return this->next->DeleteNode(x, y);
	}
	else
		return nullptr;
}

Fruit* Fruit::ReturnNext()
{
	return this->next;
}

Fruit* Fruit::ReturnFront()
{
	return this->front;
}

COORD Fruit::ReturnPos()
{
	return pos;
}

bool Fruit::CheckFruit(size_t x, size_t y)
{
	if (this->pos.X == x && this->pos.Y == y)
	{
		return true;
	}
	if (this->next != nullptr)
	{
		return this->next->CheckFruit(x, y);
	}
	else
		return false;
}


